#pragma once
#include"RBTree.h"
namespace zjs 
{
	template <class K,class V>
	class map {
	public:
		struct MapOfKey
		{
			const V& operator()(const pair<K,V>& kv)
			{
				return kv.second;
			}
		};

		typedef typename RBTree<pair<const K, V>, MapOfKey>::iterator iterator;
		typedef typename RBTree<pair<const K, V>, MapOfKey>::const_iterator const_iterator;
		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}

		iterator begin() const
		{
			return _t.Begin();
		}

		iterator end() const
		{
			return _t.End();
		}

		pair<iterator, bool> insert(const pair<K,V>& data)
		{
			return _t.Insert(data);
		}


		V& operator[](const K&key)
		{
			auto it = _t.Insert(make_pair(key,V()));
			return it.first->second;
		}
	private:
		RBTree<pair<const K, V>, MapOfKey>_t;
	};
}